package com.service.socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2021-01-16 21:03
 **/
public class ServerSocketMy {
    public static void main(String[] args) throws IOException {
        //初始化服务端socket并绑定9999端口
        ServerSocket serverSocket = new ServerSocket(9999);
        //等待客户端连接
        Socket socket = serverSocket.accept();

        //获取输入流
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "utf-8"));
        //读取一行数据
        String line;
        //循环读
        while ((line = br.readLine()) != null) {
            //打印
            System.out.println(line);
        }


    }

}
